﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Sunscreen
{
    class Crosshair
    {
        Texture2D texture;
        Vector2 position;
        Rectangle boundingRectangle;
        Vector2 centerOffset;
        float scale = 1f;
        Viewport viewport;

        public Crosshair(ContentManager content, Vector2 position, Viewport viewport)
        {
            texture = content.Load<Texture2D>("sprites/crosshair");
            this.viewport = viewport;
            centerOffset = new Vector2(texture.Width/2, texture.Height/2);
            this.position = position - (centerOffset * scale);
            boundingRectangle = new Rectangle((int)position.X, (int)position.Y, texture.Width * (int)scale, texture.Height * (int)scale);
            Mouse.SetPosition(viewport.Width / 2, viewport.Height / 2); 
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(texture, position, null, Color.White, 0, new Vector2(0, 0), scale, SpriteEffects.None, 0);
        }

        public void Update(GameTime gameTime)
        {
            if (Mouse.GetState().X < 0)
                Mouse.SetPosition(0, Mouse.GetState().Y);
            if (Mouse.GetState().X > viewport.Width)
                Mouse.SetPosition(viewport.Width, Mouse.GetState().Y);
            if (Mouse.GetState().Y < 0)
                Mouse.SetPosition(Mouse.GetState().X, 0);
            if (Mouse.GetState().Y > viewport.Height)
                Mouse.SetPosition(Mouse.GetState().X, viewport.Height);
            position = new Vector2(Mouse.GetState().X - (texture.Width / 2), Mouse.GetState().Y - (texture.Height / 2));
        }

    }
}
